package com.asap.demo;

import com.asap.demo.rete.ReteDemo4;
import com.asap.demo.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.*;

/**
 * @author wangbh
 * @Description: TODO
 * @date 2021/11/19 15:45
 */
public class ReadCsdnNet {

    public static class MyThread implements Runnable {
        private List<String> urls;

        public MyThread(List<String> url) {
            this.urls = url;
        }


        @Override
        public void run() {

            try {
                Utils.testForUrl(urls);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    /**
     * 以行为单位读取文件，常用于读面向行的格式化文件
     */
    public static List<String> readFileByLines(String fileName) {
        List<String> list = new ArrayList<>();
        File file = new File(fileName);
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int line = 1;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                list.add(tempString);
                System.out.println(tempString);

            }

            reader.close();

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        return list;
    }
    public static void main(String[] args) {
        System.out.println("start......");
        ExecutorService threadPool = Executors.newFixedThreadPool(6);
        Properties pps = new Properties();
        InputStream in = null;
        ArrayList<String> listInput = (ArrayList<String>) readFileByLines("F:\\learning\\Project\\code\\java\\gitee\\flink\\flink-demo\\conf\\csdn.cfg");


        for (int i = 0, cnt = 0; i < 4; i++, cnt++) {
            MyThread task = new MyThread(listInput);
            threadPool.submit(task);
        }
        System.out.println("end......");

    }


}
